package makecode

import (
	"fmt"
	"gitee.com/ichub/gofactroy/common/dbcontent"
	"gitee.com/ichub/gofactroy/common/ichubbase"
	"gitee.com/ichub/gofactroy/factroy/buildfactroy"
	"gitee.com/ichub/gofactroy/factroy/buildfactroy/join"
	"gitee.com/ichub/gofactroy/factroy/dbfactroy"
)

/*
	有芯电子数据使用
*/
import (
	_ "github.com/go-sql-driver/mysql"
	_ "github.com/jinzhu/gorm/dialects/postgres"
)

func pgDBUrl() string {
	return fmt.Sprintf("host=%s port=%d shop-test=%s dbname=%s password=%s sslmode=disable ",
		"192.168.1.53", 54321, "postgres", dbname, "password")
}

var dbname = "cms"

func roachDBUrlConn() string {

	return "postgresql://root@192.168.4.119:26257/cms?sslmode=disable"

}

func pgDBUrlConn() string {
	return fmt.Sprintf("host=%s port=%d shop-test=%s dbname=%s password=%s sslmode=require",
		"192.168.13.235", 26257, "test", dbname, "123456")
}

func Gobuild() {

	dbinst, cfg := dbcontent.InitDB_Config()
	defer dbinst.Close()
	dbfactroy.InitPathMysql()
	dbfactroy.InitMap(cfg.Datasource.DriverName == "mysql")
	dbfactroy.ReCreateDirs()

	tabletool := &dbfactroy.DbFactroy{
		Author:       "leijianming",
		Dbtype_mysql: cfg.Datasource.DriverName == "mysql",
		Db:           cfg.Datasource.Database,
		Table:        "sys_dept",
		ModuleName:   ichubbase.MODULE_MAP[ichubbase.APP],
	}
	fmt.Println(tabletool.ToString())
	tool := &buildfactroy.BuildGoFactroy{DbFactroy: tabletool}

	//var entity model.TableName1
	//entity.AutoMigrate(dbcontent.GetDB())
	//单表生成
	tool.BuildTable()

	//全表生成
	tool.BuildTables()
	//关联生成
	func() {

		mtq := &join.JoinQuery{}
		mtq.Ini(tabletool, "cms_column,cms_content")
		mtq.SelectFields("cms_column.id,cms_content.content_id")
		mtq.Keys["cms_column.id"] = "cms_content.content_id"

		mtq.Build(tabletool)
	}()

	//basetest.DemoDataSaveFindPG()
	var x int
	fmt.Scanln(&x)

}
